#ifndef LCD_H_
#define LCD_H_

typedef   signed  char         int8_t;  //  标准表达方式 signed char 被等同于 int8_t；
typedef   signed short int     int16_t;
typedef   signed  int          int32_t;//在32位环境里，int代表4个字节32位！！
typedef   unsigned char         uint8_t;
typedef   unsigned short int    uint16_t;
typedef   unsigned int          uint32_t;
typedef   uint32_t   u32;///32位
typedef   uint16_t   u16;///16位
typedef   uint8_t     u8;///8位


#define XSIZE_PHYS 800
#define YSIZE_PHYS 480

#define D0_Port      GPIOA
#define D0_PIN       12

#define D1_Port      GPIOA
#define D1_PIN       11

#define D2_Port      GPIOG
#define D2_PIN       11

#define D3_Port      GPIOA
#define D3_PIN       0

#define D4_Port      GPIOA
#define D4_PIN       2

#define D5_Port      GPIOA
#define D5_PIN       3
 
#define D6_Port      GPIOC
#define D6_PIN       0

#define D7_Port      GPIOC
#define D7_PIN       1

#define D8_Port      GPIOC
#define D8_PIN       2

#define D9_Port      GPIOA
#define D9_PIN       19

#define D10_Port     GPIOA
#define D10_PIN      20

#define D11_Port     GPIOA
#define D11_PIN      21

#define D12_Port     GPIOA
#define D12_PIN      9

#define D13_Port     GPIOG
#define D13_PIN      6

#define D14_Port     GPIOG
#define D14_PIN      7

#define D15_Port     GPIOA
#define D15_PIN      6

#define RD_Port     GPIOG
#define RD_PIN      8

#define RS_Port     GPIOG
#define RS_PIN      9

#define WR_Port     GPIOA
#define WR_PIN      1

#define CS_Port     GPIOC
#define CS_PIN      3

#define BL_Port     GPIOA
#define BL_PIN      17

#define RST_Port     GPIOA
#define RST_PIN      18


typedef union
  {
  	struct
  	{
	  unsigned bit15                : 1;
	  unsigned bit14                : 1;
	  unsigned bit13                : 1;
	  unsigned bit12                : 1;
	  unsigned bit11                : 1;
	  unsigned bit10                : 1;
	  unsigned bit9                 : 1;
	  unsigned bit8                 : 1;
      unsigned bit7                 : 1;
	  unsigned bit6                 : 1;
	  unsigned bit5                 : 1;
	  unsigned bit4                 : 1;
	  unsigned bit3                 : 1;
	  unsigned bit2                 : 1;
	  unsigned bit1                 : 1;
	  unsigned bit0                 : 1;
  	}bit_type;
  	unsigned int HREG;
}REGS;

#define regbit0 	Fictitious_REG.bit_type.bit0 
#define regbit1 	Fictitious_REG.bit_type.bit1
#define regbit2	    Fictitious_REG.bit_type.bit2
#define regbit3	    Fictitious_REG.bit_type.bit3
#define regbit4 	Fictitious_REG.bit_type.bit4
#define regbit5	    Fictitious_REG.bit_type.bit5
#define regbit6	    Fictitious_REG.bit_type.bit6
#define regbit7 	Fictitious_REG.bit_type.bit7
#define regbit8	    Fictitious_REG.bit_type.bit8
#define regbit9	    Fictitious_REG.bit_type.bit9
#define regbit10	Fictitious_REG.bit_type.bit10
#define regbit11	Fictitious_REG.bit_type.bit11
#define regbit12	Fictitious_REG.bit_type.bit12
#define regbit13	Fictitious_REG.bit_type.bit13
#define regbit14	Fictitious_REG.bit_type.bit14
#define regbit15	Fictitious_REG.bit_type.bit15
#define REGDATA     Fictitious_REG.HREG


#define LCD_CS(a)	\
						if (a)	\
						GPIO_SetBits(CS_Port,CS_PIN); \
						else		\
						GPIO_ResetBits(CS_Port,CS_PIN);
#define LCD_RS(a)	\
						if (a)	\
						GPIO_SetBits(RS_Port,RS_PIN);	\
						else		\
						GPIO_ResetBits(RS_Port,RS_PIN);						
#define LCD_WR(a)	\
						if (a)	\
						GPIO_SetBits(WR_Port,WR_PIN);	\
						else		\
						GPIO_ResetBits(WR_Port,WR_PIN);
#define LCD_RD(a)	\
						if (a)	\
						GPIO_SetBits(RD_Port,RD_PIN);	\
						else		\
						GPIO_ResetBits(RD_Port,RD_PIN);

#define Set_Rst GPIO_SetBits(RST_Port,RST_PIN)
#define Clr_Rst GPIO_ResetBits(RST_Port,RST_PIN)

#define Lcd_Light_ON   GPIO_SetBits(BL_Port,BL_PIN)  // 背光打开
#define Lcd_Light_OFF  GPIO_ResetBits(BL_Port,BL_PIN)  // 背光关闭

////*************  24位色（1600万色）定义 *************//
//#define White          0xFFFFFF
//#define Black          0x000000
//#define Blue           0x0000FF
//#define Blue2          0x3F3FFF
//#define Red            0xFF0000
//#define Magenta        0xFF00FF
//#define Green          0x00FF00
//#define Cyan           0x00FFFF
//#define Yellow         0xFFFF00						
				

//*************  16位色定义 *************//
#define White          0xFFFF
#define Black          0x0000
#define Blue           0x001F
#define Blue2          0x051F
#define Red            0xF800
#define Magenta        0xF81F
#define Green          0x07E0
#define Cyan           0x7FFF
#define Yellow         0xFFE0
						
						

void LCD_Initial(void); //LCD初始化函数
void LCD_delay(int time);
void WriteComm(unsigned char CMD);
void WriteData(u32 dat);
void LCD_WR_REG(u16 Index,u16 CongfigTemp);
void Lcd_ColorBox(u16 xStart,u16 yStart,u16 xLong,u16 yLong,u32 Color);
//void SPILCD_DrawLine(unsigned short x1,unsigned short y1,unsigned short x2,unsigned short y2,unsigned short color);
//void SPILCD_ShowChar(unsigned short x,unsigned short y,unsigned char num, unsigned int fColor, unsigned int bColor,unsigned char flag) ;
void LCD_PutString(unsigned short x, unsigned short y, char *s, unsigned int fColor, unsigned int bColor,unsigned char flag);
void LCD_Fill_Pic(u16 x, u16 y,u16 pic_H, u16 pic_V, const unsigned int*  pic);



#endif